package com.tojabo.piano;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

import com.tojabo.util.SystemUtil;


public class PianoPanel extends JPanel{

	private static final long serialVersionUID = 1L;
	
	private KeyboardPanel pan1;
	private JPanel keyboardPanel1;
	private KeyboardPanel pan2;
	private JPanel keyboardPanel2;
	private KeyboardPanel pan3;
	private JPanel keyboardPanel3;
	
	private int position_x=5;
	private int position_y=10;
	
	private ImageIcon white_down = SystemUtil.createImageIcon("white_down.png");
	private ImageIcon white_up = SystemUtil.createImageIcon("white_up.png");
	
	private List<KeyboardPanel> panelist = new ArrayList<KeyboardPanel>();
	
	public PianoPanel(){
		this.setLayout(null);
		pan1 = new KeyboardPanel(1);
		keyboardPanel1 = pan1.getPanel();
		
		pan2 = new KeyboardPanel(8);
		keyboardPanel2 = pan2.getPanel();
		pan3 = new KeyboardPanel(15);
		keyboardPanel3 = pan3.getPanel();
		
		
		panelist.add(pan1);
		panelist.add(pan2);
		panelist.add(pan3);
		
		init();
		this.add(keyboardPanel1);
		this.add(keyboardPanel2);
		this.add(keyboardPanel3);
	}
	
	private void init() {
		keyboardPanel1.setBounds(position_x,position_y+100,420,270);
		keyboardPanel2.setBounds(position_x+430,position_y+100,420,270);
		keyboardPanel3.setBounds(position_x+860,position_y+100,420,270);
		
	}
	
	public void changeButImg(int global_index,int but_status){
		
		int pan_index = global_index/7;
		int but_index = global_index % 7;
		
		KeyboardPanel keyPanel = getKeyboardPanel(pan_index);		
		keyPanel.changeButImg(but_index, but_status);
	}
	
	private KeyboardPanel getKeyboardPanel(int index){
		return panelist.get(index);
	}
}
